<template>
	<view class="content">
		<view class="searchTop">
			<view class="pb10 pl30 pr30">
				<view class="searchBody" :style="searchBodyStyle">
					<image class="logo" mode="aspectFit" src="/static/logo1.png"></image>
					<u-search placeholder="关键词搜索" disabled @click="jump(0)" v-model="state.keyword" :showAction='false'></u-search>
				</view>
			</view>
		</view>
		<u-popup bgColor='rgba(0,0,0,0)' :show="state.showVideo" mode='bottom' v-if="state.videoUrl" closeable @close="popClose">
			<view class="pt35">
				<view class="pt35"></view>
				<view class="pt5"></view>
				<video :src="state.videoUrl" :style="videoStyle" ></video>
			</view>
		</u-popup>
		<view class="floatIcon" @click="state.showVideo = true" v-if="state.videoUrl">
			<view class="iconText">宣传片</view>
			<!-- <view class="iconText">片</view> -->
		</view>
		<swiper class="swieprClass" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="300">
			<swiper-item v-for="(item,index) in state.swiperList" :key="index" class="w100 h100">
				<image :src="item.imgFull" mode="aspectFill" class="swiperImg w100 h100"></image>
			</swiper-item>
		</swiper>
		
		<view class="main p30">
			<view class="tabs">
				<view class="tabsItem" :style="tabsItemStyle">
					<image src="/static/logo2.png" mode="aspectFit" class="w100 h100"></image>
				</view>
					<!-- <button :key="index" :style="tabsItemStyle" v-if="index === 3" class="tabsItem btn" plain open-type="contact">{{item.name}}</button> -->
				<view v-for="(item,index) in state.handleList" :key="index+'view'" :style="tabsItemStyle" @click="jump(index)" class="tabsItem">{{item.name}}</view>
			</view>
			<view class="row mt30">
				<template v-for="(item,index) in state.handleList" :key="index">
					<!-- <button v-if="index === 3" class="col btn" plain open-type="contact">
						<squareBox :ratio='1'>
							<image :src="item.imgFull" mode="aspectFill" class="mainPic w100 h100"></image>
						</squareBox>
						<view class="mb20"></view>
						{{item.otherName}}
					</button> -->
					<view class="col" @click="jump(index)">
						<squareBox :ratio='1'>
							<image :src="item.imgFull" mode="aspectFill" class="mainPic w100 h100"></image>
						</squareBox>
						<view class="mb20"></view>
						{{item.otherName}}
					</view>
				</template>
			</view>
		</view>
		<beforeSearchWithPicture ref="beforeSearchWithPictureRef"></beforeSearchWithPicture>
		<checkAuth></checkAuth>
	</view>
</template>

<script setup>
import { computed, onMounted, reactive, ref } from 'vue';
import request from '@/utils/request.js'
	const state = reactive({
		swiperList: [],
		menuBtnSize: '',
		videoUrl: '',
		keyword: '',
		handleList: [
			// {name:'产品图库',otherName:'按分类找产品'},
			// {name:'伞形配色',otherName:'按货号找产品'},
			// {name:'以图搜图',otherName:'拍摄找产品'},
			// {name:'联系客服',otherName:'客服人工找产品',type:'contact'},
		],
		showVideo: false
	})
	const popClose = () => {
		state.showVideo = false
	}
	const tabsItemStyle = computed(() => {
		return {
			width: 1/(state.handleList.length + 1) * 100 + '%'
		}
	})
	const getConfig = () => {
		request({
			url:'api/home/homeMsg'
		}).then(res => {
			state.swiperList = res.banner;
			state.handleList = res.column;
			state.videoUrl = res.videoUrl
		})
	}
	getConfig()
	// 跳转
	const beforeSearchWithPictureRef = ref(null)
	const jump = (index) => {
		switch (index){
			case 0:
			// 按产品编号
				uni.navigateTo({
					url: '/pages/class/searchProductByNumber'
				})
				break;
			case 1:
			// 以图搜图
				beforeSearchWithPictureRef.value.checkUserinfo()
				break;
			case 2:
			// 按分类
			uni.switchTab({
				url: '/pages/class/class'
			})
				break;
			case 3:
			// 关于我们
			uni.navigateTo({
				url: '/pages/index/aboutUs'
			})
				break;
			default:
				break;
		}
	}
	const videoStyle = computed(() => {
		const { top, height } = state.menuBtnSize;
		return {
			width: '750rpx',
			height: `calc(100vh - ${top + height + 35}px)`,
			display: 'block'
		}
	})
	// 搜索栏高度
	const searchBodyStyle = computed(() => {
		if(!state.menuBtnSize) {
			return ''
		}else {
			const { top, height } = state.menuBtnSize;
			return {
				paddingTop: `${top + height + 5}px`
			}
		}
	})
	onMounted(() => {
		// #ifdef MP-WEIXIN
		state.menuBtnSize = uni.getMenuButtonBoundingClientRect()
		// #endif
	})
</script>

<style lang="scss" scoped>
	.content {
		.searchTop {
			background-color: #006767;
			position: sticky;
			top: 0;
			z-index: 1;
			/* #ifdef H5 */
			padding-top: 10rpx;
			/* #endif */
			.searchBody {
				display: flex;
				align-items: center;
				.logo {
					width: 180rpx;
					height: 50rpx;
					margin-right: 20rpx;
				}
			}
		}
		.floatIcon {
			$s: 80rpx;
			font-size: 24rpx;
			width: $s;
			height: $s;
			border-radius: 50%;
			text-align: center;
			position: fixed;
			background-color: $main-color;
			color: #fff;
			z-index: 10;
			right: 10rpx;
			bottom: 30rpx;
			/* #ifdef H5 */
			bottom: 130rpx;
			/* #endif */
			display: flex;
			justify-content: center;
			flex-direction: column;
			align-items: center;
			// .iconText {
			// 	line-height: $s * 0.5;
			// }
		}
		.swieprClass {
			height: 380rpx;
			.swiperImg {
				width: 100%;
				height: 100%;
			}
		}
		.main {
			.tabs {
				display: flex;
				align-items: center;
				.tabsItem {
					width: 20%;
					flex-shrink: 0;
					text-align: center;
					font-size: 26rpx;
					color: #333;
					$h: 50rpx;
					height: $h;
					line-height: $h;
					font-weight: 600;
					&.btn {
						border: none;
						background-color: rgba(0, 0, 0, 0);
						text-align: center;
						padding: 0;
						color: #333;
					}
				}
			}
			.row {
				@include row(30rpx);
				.col {
					@include col(12,30rpx);
					text-align: center;
					line-height: 1;
					margin-bottom: 30rpx;
					font-size: 28rpx;
					font-weight: 600;
					&.btn {
						border: none;
					}
					.mainPic {
						display: block;
						border-radius: 16rpx;
					}
				}
			}
		}
	}
</style>
